package part18;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

/**
 * @author wcj
 * @Date 2021/6/4 16:01
 * @Version 1.0
 */
public class Part1824 {

    private static final int SIZE = 1024;

    /**
     * ByteBuffer是底层的数据结构，其上还有不同类型的缓冲视图，例如Char,Short,Int,Long等等
     * 我们可以通过获取缓冲视图然后直接操作底层的ByteBuffer
     *
     * @param args
     */
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(SIZE);
        IntBuffer intBuffer = buffer.asIntBuffer();
        intBuffer.put(new int[]{11, 22, 33, 44, 55, 66});
        System.out.println(intBuffer.get(3));
        intBuffer.put(3, 1811);
        intBuffer.flip();
        while (intBuffer.hasRemaining()) {
            int i = intBuffer.get();
            System.out.println(i);
        }
    }
}
